


#ifndef PF_BLOCKLIST_H
#define PF_BLOCKLIST_H


#include <QList>
#include <QString>
#include "lx_Export.h"

class PF_Block;
class PF_BlockListObserver;

/**
 * List of blocks.
 *
 * @see PF_Block
 *

 */
class LX_EXPORT PF_BlockList {
public:
    PF_BlockList(bool owner=false);
    virtual ~PF_BlockList() {}

    void clear();
    /**
     * @return Number of blocks available.
     */
    int count() {
        return blocks.count();
    }

    /**
     * @return Block at given position or NULL if i is out of range.
     */
    PF_Block* at(int i) {
        return blocks.at(i);
    }

    void activate(const QString& name);
    void activate(PF_Block* block);
    //! @return The active block of NULL if no block is activated.
    PF_Block* getActive() {
        return activeBlock;
    }

    virtual bool add(PF_Block* block, bool notify=true);
    virtual void addNotification();
    virtual void remove(PF_Block* block);
    virtual bool rename(PF_Block* block, const QString& name);
    //virtual void editBlock(PF_Block* block, const PF_Block& source);
    PF_Block* find(const QString& name);
    QString newName(const QString& suggestion = "");
    void toggle(const QString& name);
    void toggle(PF_Block* block);
    void freezeAll(bool freeze);

    /**
     * @return First block of the list.
     */
    //PF_Block* firstBlock() {
    //    return blocks.first();
    //}

    /**
     * @return Next block from the list after 
     * calling firstBlock() or nextBlock().
     */
    //PF_Block* nextBlock() {
    //    return blocks.next();
    //}

    void addListener(PF_BlockListObserver* listener);
    void removeListener(PF_BlockListObserver* listener);
	
	/**
	 * Sets the layer lists modified status to 'm'.
	 */
	void setModified(bool m) {
		modified = m;
	}
	
	/**
	 * @retval true The layer list has been modified.
	 * @retval false The layer list has not been modified.
	 */
    virtual bool isModified() const {
        return modified;
    }

    friend std::ostream& operator << (std::ostream& os, PF_BlockList& b);

private:
    //! Is the list owning the blocks?
    bool owner;
    //! Blocks in the graphic
    QList<PF_Block*> blocks;
    //! List of registered BlockListListeners
    QList<PF_BlockListObserver*> blockListListeners;
    //! Currently active block
    PF_Block* activeBlock;
    /** Flag set if the layer list was modified and not yet saved. */
    bool modified;
};

#endif
